package com.ingesup.caribou.server.generator;

public class SinusCardinalTheoricalGenerator extends TheoricalGenerator {
	
	public static final double DEFAULT_MAX_AMPL=10;
	public static final double DEFAULT_APERTURE=3;
	public static final String[] PARAMS=new String[]{"MAX_AMPL","APERTURE"};
	
	private double maxAmpl=DEFAULT_MAX_AMPL;
	private double aperture=DEFAULT_APERTURE;
	
	public String[] getParameters() {
		return PARAMS;
	}

	public void changeParameter(String param, String value) {
		if(param == PARAMS[0]){
			maxAmpl=Double.parseDouble(value);
		}
		if(param == PARAMS[1]){
			aperture=Double.parseDouble(value);
		}	
	}

	@Override
	public double compute(double x, double y) {
		double lambda=3e8/9e9;
		double rTheta=3.0/360.0*2.0*Math.PI;//rayon du lob principal en theta
		double l=lambda*0.886/rTheta;//largeur du lob principal
		double rPhi=aperture/360.0*2.0*Math.PI;//rayon du lob principal en phi
		double L=lambda*0.886/rPhi;//largeur du lob principal
		double E0=maxAmpl;//Gain maximum
		double r=10.0;//distance de mesure		
		double a = 0.0;
		double p = 0.0;
		if(x<-180){
			x=-180;
		}
		else if(x>180){
			x=180;			
		}
		if(y<-90){
			y=-90;
		}
		else if(y>90){
			y=90;			
		}
		double theta=(x/2)*Math.PI-Math.PI/2;
		double phi=(y)*Math.PI-Math.PI/2;
		double sinc1=Math.PI*(L/lambda)*Math.sin(phi)*Math.cos(theta);
		sinc1=((sinc1==0)?1:Math.sin(sinc1)/sinc1);
		double sinc2=Math.PI*(l/lambda)*Math.sin(theta);
		sinc2=((sinc2==0)?1:Math.sin(sinc2)/sinc2);
		a=E0*((l*L)/(lambda*r))*sinc1*sinc2;
		p=phi/(Math.PI)*360*Math.cos(theta);
		double amplitude = a;
		return amplitude;
	}
}
